#!/usr/bin/env python
# -*- coding:utf-8 -*-
__author__ = 'shawn'

import tornado.web
import tornado.ioloop

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write('<html><body><form action="/" method="post">'
                   '<input type="text" name="message">'
                   '<input type="submit" value="Submit">'
                   '</form></body></html>')
    def post(self, *args, **kwargs):
        self.set_header("Content-Type", "text/plain")
        self.write("You wrote " + self.get_argument('message'))
        self.write(self.request)

class StoryHandler(tornado.web.RequestHandler):
    def get(self, story_id):
        self.write("Your requested the story "+ story_id)

class RedirctHandler(tornado.web.RequestHandler):
    def get(self, *args, **kwargs):
        self.redirect('www.sohu.com')


application = tornado.web.Application([
    (r'/',MainHandler),
    (r'/story/([0-9]+)',StoryHandler),
    (r'/redict',RedirctHandler),
])

if __name__ == "__main__":
    application.listen(9999)
    tornado.ioloop.IOLoop.instance().start()